<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body style="height: 3000px;">
  <div id="app">
    <button @click="showHide">{{isShow?'消失':'显示'}}</button>
    <home v-if="isShow"></home>
  </div>
  <script src="./vue.js"></script>
  <script>
    
    const Home = {
      template: `
        <div>
          <button @click="addLi">增加li</button>
          <ul ref="oul">
            <li v-for="item in arr" :key="item">
              {{ item }}  
            </li>
          </ul>
        </div>
      `,
      methods: {
        addLi(){
          this.arr.push(this.arr.length+1)
        }
      },
      data(){
        return {
          arr: [1,2,3,4],
          timer: null
        }
      },
      beforeCreate(){
        console.log('组件初始化之前--beforeCreate');
      },
      created(){
        console.log('组件初始化完成--created');
      },
      beforeMount(){
        console.log('视图渲染之前--beforeMount');
      },
      mounted(){
        console.log('视图已经渲染完成--mounted');
        this.timer =   setInterval(() => {
          console.log(111);
        }, 1000);
        window.onscroll = function(){
          var sTop = document.documentElement.scrollTop||document.body.scrollTop;
          console.log(sTop);
        }
      },
      beforeUpdate(){
        console.log('数据变化视图更新之前---beforeUpdate');
      },
      updated(){
        console.log('数据变化视图更新完成---updated');
        
      },
      beforeDestroy(){
        clearInterval(this.timer);
        window.onscroll = null;
        console.log('组件卸载之前');
      },
      destroyed(){
        console.log('组件已经卸载');
      }
    }
    Vue.component('Home', Home);
  
    const vm = new Vue({
      el: '#app',
      data: {
        isShow: true
      },
      methods: {
        showHide(){
          this.isShow = !this.isShow;
        }
      }
    })
  </script>
</body>

</html>